const Router = require('@koa/router');
const uploadController = require('../../controllers/uploadController');
const { authenticate } = require('../../middleware/authMiddleware');

const router = new Router({
    prefix: '/api/upload'
});

/**
 * @swagger
 * /api/upload/avatar:
 *   post:
 *     summary: 上传头像（无需验证）
 *     tags: [Upload]
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             properties:
 *               file:
 *                 type: string
 *                 format: binary
 */
router.post('/avatar', uploadController.uploadAvatar);

/**
 * @swagger
 * /api/upload/avatar/delete:
 *   post:
 *     summary: 删除头像（无需验证）
 *     tags: [Upload]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - fileUrl
 *             properties:
 *               fileUrl:
 *                 type: string
 *                 description: 文件URL或key
 *           example:
 *             fileUrl: "http://qiniu.giovan.top/avatars/xxx.jpg"
 */
router.post('/avatar/delete', uploadController.deleteAvatar);

/**
 * @swagger
 * /api/upload/file:
 *   post:
 *     summary: 上传文件（需要验证）
 *     tags: [Upload]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             properties:
 *               file:
 *                 type: string
 *                 format: binary
 */
router.post('/file', authenticate, uploadController.uploadFile);

/**
 * @swagger
 * /api/upload/file/{key}:
 *   delete:
 *     summary: 删除文件（需要验证）
 *     tags: [Upload]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: key
 *         required: true
 *         schema:
 *           type: string
 *         description: 文件的key
 */
router.delete('/file/:key', authenticate, uploadController.deleteFile);

module.exports = router; 